using System;
using System.Runtime.InteropServices;
using System.Security;

namespace Jodell.Transport.Ethercat
{
    public class EcMain
    {
        public const string NATIVE_DLL_NAME = "SOEM_Wrapper.dll";


        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_setupdatagram(IntPtr port, IntPtr frame, byte com, byte idx, ushort ADP, ushort ADO, ushort length, IntPtr data);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_adddatagram(IntPtr port, IntPtr frame, byte com, byte idx, bool more, ushort ADP, ushort ADO, ushort length, IntPtr data);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_BWR(IntPtr port, ushort ADP, ushort ADO, ushort length, IntPtr data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_BRD(IntPtr port, ushort ADP, ushort ADO, ushort length, IntPtr data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_APRD(IntPtr port, ushort ADP, ushort ADO, ushort length, IntPtr data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_ARMW(IntPtr port, ushort ADP, ushort ADO, ushort length, IntPtr data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_FRMW(IntPtr port, ushort ADP, ushort ADO, ushort length, IntPtr data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern ushort ecx_APRDw(IntPtr port, ushort ADP, ushort ADO, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_FPRD(IntPtr port, ushort ADP, ushort ADO, ushort length, IntPtr data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern ushort ecx_FPRDw(IntPtr port, ushort ADP, ushort ADO, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_APWRw(IntPtr port, ushort ADP, ushort ADO, ushort data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_APWR(IntPtr port, ushort ADP, ushort ADO, ushort length, IntPtr data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_FPWRw(IntPtr port, ushort ADP, ushort ADO, ushort data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_FPWR(IntPtr port, ushort ADP, ushort ADO, ushort length, IntPtr data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_LRW(IntPtr port, uint LogAdr, ushort length, IntPtr data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_LRD(IntPtr port, uint LogAdr, ushort length, IntPtr data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_LWR(IntPtr port, uint LogAdr, ushort length, IntPtr data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_LRWDC(IntPtr port, uint LogAdr, ushort length, IntPtr data, ushort DCrs, out long DCtime, int timeout);


        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ecx_SDOerror(IntPtr context, ushort Slave, ushort Index, byte SubIdx, int AbortCode);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_SDOread(IntPtr context, ushort slave, ushort index, byte subindex, bool CA, ref int psize, IntPtr p, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_SDOwrite(IntPtr context, ushort Slave, ushort Index, byte SubIndex, bool CA, int psize, IntPtr p, int Timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_RxPDO(IntPtr context, ushort Slave, ushort RxPDOnumber, int psize, IntPtr p);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_TxPDO(IntPtr context, ushort slave, ushort TxPDOnumber, ref int psize, IntPtr p, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_readPDOmap(IntPtr context, ushort Slave, out int Osize, out int Isize);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_readPDOmapCA(IntPtr context, ushort Slave, int Thread_n, out int Osize, out int Isize);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_readODlist(IntPtr context, ushort Slave, IntPtr pODlist);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_readODdescription(IntPtr context, ushort Item, IntPtr pODlist);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_readOEsingle(IntPtr context, ushort Item, byte SubI, IntPtr pODlist, IntPtr pOElist);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_readOE(IntPtr context, ushort Item, IntPtr pODlist, IntPtr pOElist);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_config_init(IntPtr context, byte usetable);



        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_config_map_group(IntPtr context, IntPtr pIOmap, byte group);


        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_config_overlap_map_group(IntPtr context, IntPtr pIOmap, byte group);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_recover_slave(IntPtr context, ushort slave, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_reconfig_slave(IntPtr context, ushort slave, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool ecx_configdc(IntPtr context);


        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ecx_dcsync0(IntPtr context, ushort slave, bool act, uint CyclTime, int CyclShift);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ecx_dcsync01(IntPtr context, ushort slave, bool act, uint CyclTime0, uint CyclTime1, int CyclShift);


        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr ecx_elist2string(IntPtr context);


        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ecx_pusherror(IntPtr context, IntPtr Ec);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool ecx_poperror(IntPtr context, IntPtr Ec);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool ecx_iserror(IntPtr context);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ecx_packeterror(IntPtr context, ushort Slave, ushort Index, byte SubIdx, ushort ErrorCode);


        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_init(IntPtr context, [MarshalAs(UnmanagedType.LPStr)] string ifname);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_init_redundant(IntPtr context, IntPtr redport, [MarshalAs(UnmanagedType.LPStr)] string ifname, [MarshalAs(UnmanagedType.LPStr)] string if2name);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ecx_close(IntPtr context);


        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern byte ecx_siigetbyte(IntPtr context, ushort slave, ushort address);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern short ecx_siifind(IntPtr context, ushort slave, ushort cat);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ecx_siistring(IntPtr context, [MarshalAs(UnmanagedType.LPStr)] string str, ushort slave, ushort Sn);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern ushort ecx_siiFMMU(IntPtr context, ushort slave, IntPtr FMMU);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern ushort ecx_siiSM(IntPtr context, ushort slave, IntPtr SM);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern ushort ecx_siiSMnext(IntPtr context, ushort slave, IntPtr SM, ushort n);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_siiPDO(IntPtr context, ushort slave, IntPtr PDO, byte t);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_readstate(IntPtr context);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_writestate(IntPtr context, ushort slave);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern ushort ecx_statecheck(IntPtr context, ushort slave, ushort reqstate, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_mbxempty(IntPtr context, ushort slave, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_mbxsend(IntPtr context, ushort slave, IntPtr mbx, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_mbxreceive(IntPtr context, ushort slave, IntPtr mbx, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ecx_esidump(IntPtr context, ushort slave, out byte esibuf);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern uint ecx_readeeprom(IntPtr context, ushort slave, ushort eeproma, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_writeeeprom(IntPtr context, ushort slave, ushort eeproma, ushort data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_eeprom2master(IntPtr context, ushort slave);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_eeprom2pdi(IntPtr context, ushort slave);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern ulong ecx_readeepromAP(IntPtr context, ushort aiadr, ushort eeproma, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_writeeepromAP(IntPtr context, ushort aiadr, ushort eeproma, ushort data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern ulong ecx_readeepromFP(IntPtr context, ushort configadr, ushort eeproma, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_writeeepromFP(IntPtr context, ushort configadr, ushort eeproma, ushort data, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ecx_readeeprom1(IntPtr context, ushort slave, ushort eeproma);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern uint ecx_readeeprom2(IntPtr context, ushort slave, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_send_overlap_processdata_group(IntPtr context, byte group);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_receive_processdata_group(IntPtr context, byte group, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_send_processdata(IntPtr context);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_send_overlap_processdata(IntPtr context);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_receive_processdata(IntPtr context, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_send_processdata_group(IntPtr context, byte group);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_SoEread(IntPtr context, ushort slave, byte driveNo, byte elementflags, ushort idn, ref int psize, IntPtr p, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_SoEwrite(IntPtr context, ushort slave, byte driveNo, byte elementflags, ushort idn, int psize, IntPtr p, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_readIDNmap(IntPtr context, ushort slave, out int Osize, out int Isize);



        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ec_config_init(byte usetable);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pIOmap">Map Size</param>
        /// <returns></returns>
        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ec_config_map(IntPtr pIOmap);
        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool ec_configdc();
        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr ec_sdoerror2string(uint sdoerrorcode);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr ec_ALstatuscode2string(ushort ALstatuscode);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr ec_soeerror2string(ushort errorcode);
        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr ec_find_adapters();

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ec_free_adapters(IntPtr adapter);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern byte ec_nextmbxcnt(byte cnt);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ec_clearmbx(IntPtr Mbx);
        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ec_init([MarshalAs(UnmanagedType.LPStr)] string ifname);
        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ec_close();


        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr get_ec_context();

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr get_ec_slave(int slaveno = 0);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int request_state(int slave, UInt16 state);
        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int get_state(int slave);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int Test([MarshalAs(UnmanagedType.LPStr)] string ifname);
        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int config_map();
        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ecatcheck();


        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_FOEread(IntPtr context, UInt16 slave, [MarshalAs(UnmanagedType.LPStr)] string filename, UInt32 password, ref int psize, IntPtr p, int timeout);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ecx_FOEwrite(IntPtr context, UInt16 slave, [MarshalAs(UnmanagedType.LPStr)] string filename, UInt32 password, int psize, IntPtr p, int timeout);


        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GetSlaves(IntPtr slaves, ref int count);


        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ScanDevice([MarshalAs(UnmanagedType.LPStr)] string ifname);
        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int Stop();

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ScanDevice01([MarshalAs(UnmanagedType.LPStr)] string ifname, IntPtr data);

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr GetIOMap();

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern int get_ec_slavecount();

        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool AllInOp();
        [SuppressUnmanagedCodeSecurity]
        [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ReadAllSlaveState(IntPtr states);
    }
}